# This file is part of the Net::Tube module.
#
# Net::Tube is Free Software; you can use, redistribute it and/or
# modify it under the terms of either:
#
# a) the GNU General Public License as published by the Free Software
#    Foundation, either version 2, or (at your opinion) any later
#    version, or
#
# b) the "Artistic License" which comes with Perl.
#
package Net::Tube::Filter::Sort::String;

use Net::Tube::Filter::Sort;
our @ISA = qw(Net::Tube::Filter::Sort);

sub compare {
    my $self      = shift;    
    my $nodeA     = shift;
    my $nodeB     = shift;
    my $direction = shift;
    
    my ($ta, $tb);
    if ( defined $nodeA ) {
        $ta = $nodeA->textContent;
    }
    unless ( defined $ta && length $ta ) {
        $ta = "";
    }
    if ( defined $nodeB ) {
        $tb = $nodeB->textContent;
    }
    unless ( defined $tb && length $tb ) {
        $tb = "";
    }
 
    my $retval = ($ta cmp $tb);
    if ( $direction == Net::Tube::Filter::Sort::DESCENDING() ) {
        $retval *= -1;
    }
    return $retval;
}

1;
